//    Copyright (C) Kherty.  All rights reserved.
using System.Collections;
using System.Collections.Generic;

namespace OpenLS.Spreadsheet
{
    class WriteObjectTable <T>: IEnumerable<T>
    {
        public void Add (T record)
        {
            if (objToKey.ContainsKey(record))
                return;
            int id = objToKey.Count;
            objToKey.Add(record, id);
            objs.Add(record);
        }

        readonly Dictionary<T, int> objToKey = new Dictionary<T, int>();
        readonly List<T> objs = new List<T>();
        public int this [T record]
        {
            get
            {
                return objToKey[record];
            }
        }

        public int Count
        {
            get { return objs.Count; }
        }

        public IEnumerator<T> GetEnumerator()
        {
            return objs.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}
